<?php

abstract class AjaxController extends Controller {

    public function __construct() {
        header('Content-type: application/json; charset=' . DEFAULT_ENCODING);
        parent::__construct();
        if (!isset($this->user)) {
            exit;
        }
    }

    /**
     *  Undefined route fallback
     */
    public function __call($name, $args) {
        exit;
    }

    public function route(callable $action/* , $verb , $args */) {
        call_user_func_array($action, $this->get_postback());
    }

    protected function view($view, $model = NULL) {
        print json_encode($view);
    }

}
